package com.yx.changdao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yx.changdao.common.entity.*;
import com.yx.changdao.common.enums.DifficultLevel;
import com.yx.changdao.common.enums.Err;
import com.yx.changdao.common.enums.IndustryCategory;
import com.yx.changdao.common.enums.ScoreEnum;
import com.yx.changdao.common.exception.AlertException;
import com.yx.changdao.common.mapper.ProblemApplyMapper;
import com.yx.changdao.common.mapper.ProblemDealMapper;
import com.yx.changdao.common.mapper.ProblemInfoMapper;
import com.yx.changdao.common.mapper.ProblemMapper;
import com.yx.changdao.common.utils.Dates;
import com.yx.changdao.common.utils.Faster;
import com.yx.changdao.common.utils.SysUtils;
import com.yx.changdao.common.vo.ProblemVo;
import com.yx.changdao.common.vo.count.input.ProblemCountGlobal;
import com.yx.changdao.common.vo.count.input.ProblemCountType;
import com.yx.changdao.common.vo.count.input.ProblemPieCount;
import com.yx.changdao.common.vo.count.leader.DeptCount;
import com.yx.changdao.common.vo.count.leader.EmpCount;
import com.yx.changdao.common.vo.count.leader.ProblemGlobal;
import com.yx.changdao.common.vo.count.leader.ProblemType;
import com.yx.changdao.common.vo.count.newleader.ExecuteCount;
import com.yx.changdao.common.vo.count.newleader.TotalCount;
import com.yx.changdao.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: <br/>
 * 问题
 * <p>
 * <br/>
 * @Auther: wangzd
 * @create 2020/04/03 16:51
 */
@Service
public class ProblemServiceImpl extends ServiceImpl<ProblemMapper, Problem> implements ProblemService {

    /**
     * 问题信息(在分配之前)服务
     */
    @Autowired
    private ProblemInfoService problemInfoService;

    /**
     * 问题上报打回记录
     */
    @Autowired
    private ProblemBeatbackService problemBeatbackService;

    /**
     * 部门
     */
    @Autowired
    private DepartmentService departmentService;

    /**
     * 申请
     */
    @Autowired
    private ProblemApplyService problemApplyService;

    /**
     * 处理结果
     */
    @Autowired
    private ProblemDealService problemDealService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    protected NoWorkdayService noWorkdayService;

    @Autowired
    protected ProblemInfoMapper problemInfoMapper;

    @Autowired
    protected ProblemDealMapper problemDealMapper;

    @Autowired
    protected ProblemApplyMapper problemApplyMapper;

    /**
     * 根据date时间基准,addNum增加的日期, 跳过非工作日; 返回办里截至时间的23:59:59
     */
    Date backDate(Date date, int addNum) {

        Calendar cal = Calendar.getInstance(Locale.CHINA);
        cal.setTime(date);
        //查询所有的非工作日 字符串形式
        List<String> noWorks = noWorkdayService.
                list(new QueryWrapper<NoWorkday>().select(NoWorkday.NO_WORKDAY)).
                stream().map(NoWorkday::getNoWorkday).collect(Collectors.toList());
        while (true) {
            if (addNum <= 0) {

                cal.set(Calendar.HOUR_OF_DAY, 23);
                cal.set(Calendar.MINUTE, 59);
                cal.set(Calendar.SECOND, 59);
                return cal.getTime();
            }
            cal.add(Calendar.DAY_OF_MONTH, 1);

            if (noWorks.contains(Dates.format().format(cal.getTime()))) {
                //非工作日 跳过
                continue;
            }
            addNum -= 1;
        }
    }

    /**
     * 计算两个日期相差天数,跳过节假日
     */
    @Override
    public Integer lastDay(Date str, Date end) {

        if (Faster.isNull(end)) {
            return 0;
        }

        if (str.getTime() >= end.getTime()) {
            return 0;
        }
        Calendar cal = Calendar.getInstance(Locale.CHINA);
        cal.setTime(str);

        //查询所有的非工作日 字符串形式
        List<String> noWorks = noWorkdayService.
                list(new QueryWrapper<NoWorkday>().select(NoWorkday.NO_WORKDAY)).
                stream().map(NoWorkday::getNoWorkday).collect(Collectors.toList());

        Integer lastDay  = 0;

        while (true) {

            if (Dates.format().format(cal.getTime()).equals(Dates.format().format(end))) {
                break;
            }

            if (cal.getTime().getTime() >= end.getTime()) {
                break;
            }

            cal.add(Calendar.DAY_OF_MONTH, 1);

            if (noWorks.contains(Dates.format().format(cal.getTime()))) {
                continue;
            }

            lastDay += 1;

            if (lastDay >= 100) {
                break;
            }
        }

        return lastDay;
    }

    @Override
    public boolean delay(Integer proId) throws AlertException {

        Problem pro = getById(proId);
        Faster.throwNull(pro, Err.NF_PROBLEM.n());

        if (pro.getIfAssign().equals(0)) {
            throw new AlertException("该问题未分配");
        }

        if (pro.getIfDelay().equals(1)) {
            throw new AlertException("只能延期一次");
        }

        if (pro.getIfTimeout().equals(1)) {
            throw new AlertException("逾期件不能延期");
        }

        pro.setIfDelay(1); //设置为已延期

        Date date = backDate(pro.getDealLimitTime(), DifficultLevel.getExtendDay(pro.getDifficultLevel()));
        pro.setDealLimitTime(date);
        pro.setIfTimeout(0); //设置未逾期

        return updateById(pro);
    }


    @Override
    public void advance(Problem problem) {

        if (Faster.isNotNull(problem)) {

            problem.setCreateTime(null);
            problem.setCreateByName(null);
            problem.setCreateBy(null);

            problem.setUpdateTime(null);
            problem.setUpdateByName(null);
            problem.setUpdateBy(null);
        }
    }

    @Override
    public boolean hangUp(Integer proId) throws AlertException {
        ProblemInfo problemInfo = problemInfoService.getById(proId);

        Faster.throwNull(problemInfo, Err.NF_PROBLEM.n());

        if (problemInfo.getIfAssign().equals(1)) {
            throw new AlertException("分配不能挂起");
        }

        if (problemInfo.getIfAllend().equals(1)) {
            throw new AlertException("已办结不能挂起");
        }

        problemInfo.setIfHangup(1); //挂起

        return problemInfoService.updateById(problemInfo);
    }

    @Override
    public boolean hangCancel(Integer proId) throws AlertException {

        ProblemInfo problemInfo = problemInfoService.getById(proId);

        Faster.throwNull(problemInfo, Err.NF_PROBLEM.n());

        if (!problemInfo.getIfHangup().equals(1)) {
            throw new AlertException("当前不是挂起状态");
        }

        problemInfo.setIfHangup(0); //取消挂起

        return problemInfoService.updateById(problemInfo);
    }

    @Override
    public List<Problem> byInfoId(Integer proInfoId) {
        return baseMapper.selectList(new QueryWrapper<Problem>().eq(Problem.PROBLEM_INFO_ID, proInfoId));
    }


    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public boolean assign(Integer proInfoId, List<Integer> depIds,String assignOpinion) throws AlertException {

        ProblemInfo problemInfo = problemInfoService.getById(proInfoId);

        Faster.throwNull(problemInfo, Err.NF_PROBLEM.n());

        if (problemInfo.getIfAssign().equals(1)) {
            throw new AlertException("问题已分配");
        }

        if (problemInfo.getIfHangup().equals(1)) {
            throw new AlertException("问题已挂起");
        }

        Set<Integer> depIds_tem = depIds.stream().collect(Collectors.toSet());

        Faster.throwNull(depIds_tem, Err.EM_DEP.n());

        Date now = Faster.now();

        Set<String> deptNames = new HashSet<>();

        for (Integer depId : depIds_tem) {

            Department dept = departmentService.getById(depId);

            Faster.throwNull(dept, Err.NF_DEPT.n());

            Problem temp = new Problem();

            BeanUtils.copyProperties(problemInfo, temp);
            advance(temp);
            // temp.setAssignOpinion(assignOpinion);
            temp.setSubmitterBy(problemInfo.getCreateBy());
            temp.setSubmitterByName(problemInfo.getCreateByName());
            temp.setSubmitterTime(problemInfo.getCreateTime());

            temp.setIfAssign(1);
            temp.setAssignTime(now);

            temp.setDepId(dept.getDepId());
            temp.setDepName(dept.getDepName());

            deptNames.add(dept.getDepName());

            saveOrUpdate(temp);
        }
        problemInfo.setDepNames(Faster.batch3(deptNames));

        problemInfo.setIfAssign(1);
        return problemInfoService.updateById(problemInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean assignRep(Integer proInfoId, List<Integer> depIds) throws AlertException {

        ProblemInfo problemInfo = problemInfoService.getById(proInfoId);

        Faster.throwNull(problemInfo, Err.NF_PROBLEM.n());

        if (problemInfo.getIfAssign().equals(0)) {
            throw new AlertException("问题未分配");
        }

        if (problemInfo.getIfHangup().equals(1)) {
            throw new AlertException("问题已挂起");
        }

        Date now = Faster.now();
        Set<Integer> depIds_tem = depIds.stream().collect(Collectors.toSet());

        Faster.throwNull(depIds_tem, Err.EM_DEP.n());

        List<Problem> problems = byInfoId(proInfoId); //旧的problem列表
        Set<Integer> collect = problems.stream().filter(p -> !p.getIfDeal().equals(0))
                .map(t -> t.getDepId()).collect(Collectors.toSet());

        //旧的problem列表
        Set<Integer> oldPro = problems.stream().map(t -> t.getDepId()).collect(Collectors.toSet());
        collect.removeAll(depIds_tem);

        if (!collect.isEmpty()) {
            Integer integer = collect.stream().findFirst().get();
            Department byId = departmentService.getById(integer);
            throw new AlertException(byId.getDepName() + "已提交处理结果,不能删除");
        }

        Set<String> deptNames = new HashSet<>();

        for (Integer depId : depIds_tem) {

            Department dept = departmentService.getById(depId);

            Faster.throwNull(dept, Err.NF_DEPT.n());

            Problem temp = new Problem();

            BeanUtils.copyProperties(problemInfo, temp);

            if (oldPro.contains(depId)) {//原本有 现在也有跳过

                deptNames.add(dept.getDepName());

                continue;
            }

            if (!oldPro.contains(depId)) { //不在原本的处理部门,添加
                advance(temp);

                temp.setSubmitterBy(problemInfo.getCreateBy());
                temp.setSubmitterByName(problemInfo.getCreateByName());
                temp.setSubmitterTime(problemInfo.getCreateTime());

                temp.setIfAssign(1);
                temp.setAssignTime(now);

                temp.setDepId(dept.getDepId());
                temp.setDepName(dept.getDepName());

                deptNames.add(dept.getDepName());

                saveOrUpdate(temp);
            }
        }

        remove(new QueryWrapper<Problem>()
                .eq(Problem.PROBLEM_INFO_ID, proInfoId)
                .eq(Problem.IF_DEAL, 0)
                .notIn(Problem.DEP_ID, depIds_tem));

        problemInfo.setDepNames(Faster.batch3(deptNames));

        return problemInfoService.updateById(problemInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean assignBatch(List<Integer> proInfoId, List<Integer> depId) throws AlertException {
        for (Integer proId : proInfoId) {
            assign(proId, depId,null);
        }
        return true;
    }

    private void setProblemInfo(Problem pro, Department department) {

        Date now = Faster.now();
        pro.setIfAssign(1);
        pro.setAssignTime(now);
        pro.setIfDeal(0);

        pro.setDepId(department.getDepId());
        pro.setDepName(department.getDepName());

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean diffOk(Integer proId) throws AlertException {

        Problem problem = getById(proId);
        Faster.throwNull(problem, Err.NF_PROBLEM.n());

        if (!problem.getDifficultLevelStatus().equals(1)) {
            throw new AlertException("办理难度状态不是待审批状态");
        }

        problem.setDifficultLevelStatus(2);

        problem.setDifficultLevelPassTime(Faster.now());

        problem.setDealLimitTime(backDate(Faster.now(),
                DifficultLevel.getFulfillDay(problem.getDifficultLevel())));

        updateById(problem);

        List<Problem> list = list(new QueryWrapper<Problem>()
                .select(Problem.ID, Problem.DIFFICULT_LEVEL_STATUS)
                .eq(Problem.PROBLEM_INFO_ID, problem.getProblemInfoId()));

        boolean match = list.stream().allMatch(t -> t.getDifficultLevelStatus().equals(2));

        if (match) {
            problemInfoService.update(new UpdateWrapper<ProblemInfo>()
                    .set(ProblemInfo.IF_DIFFICULT_LEVEL_ALLPASS, 1)
                    .eq(ProblemInfo.PROBLEM_INFO_ID, problem.getProblemInfoId()));
        }

        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean diffRefuse(Integer proId) throws AlertException {

        Problem problem = getById(proId);

        Faster.throwNull(problem, Err.NF_PROBLEM.n());

        if (!problem.getDifficultLevelStatus().equals(1)) {
            throw new AlertException("办理难度状态不是待审批状态");
        }

        problem.setDifficultLevel(""); //难度清空
        problem.setDifficultLevelStatus(3);
        updateById(problem);

        return true;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean apply(Integer proId, String applyDesc) throws AlertException {
        Problem problem = getById(proId);
        Faster.throwNull(problem, Err.NF_PROBLEM.n());
        //0-未处理 1-已处理 2-重新处理
        if (!problem.getIfDeal().equals(0)) {
            throw new AlertException("当前问题已处理,不可提交申请");
        }
        // 当一条主信息提交了疑难件申请，同时，疑难件申请状态为 待审核 、 通过的时候，不能再提交疑难件申请
        QueryWrapper<ProblemApply> qw = new QueryWrapper<ProblemApply>()
                .eq(ProblemApply.PROBLEM_INFO_ID, problem.getProblemInfoId())
                // 0-待审核 1-通过 2-不通过
                .lt(ProblemApply.APPLY_STATUS, 2);
        int count = problemApplyService.count(qw);
        if (count > 0) {
            throw new AlertException("此问题已被其他部门提交为疑难件,请勿重复提交");
        }

        ProblemApply apply = new ProblemApply();
        apply.setProblemId(problem.getId());
        apply.setCurrentDepId(SysUtils.currentUser().getDepId());
        apply.setCurrentDepName(SysUtils.currentUser().getDepName());
        apply.setProblemInfoId(problem.getProblemInfoId());
        apply.setApplyStatus(0);
        apply.setApplyDesc(applyDesc);

        problem.setDifficultStatus(1); //疑难件申请中
        updateById(problem);

        problemApplyService.save(apply);

        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submit(Integer proId, String name, String dealPhone, String context, String imgs) throws AlertException {

        Date now = Faster.now();

        Problem problem = getById(proId);
        Faster.throwNull(problem, Err.NF_PROBLEM.n());

        if (problem.getIfAssign().equals(0)) {
            throw new AlertException("该问题尚未分配");
        }

        if (problem.getIfDeal().equals(1)) {
            throw new AlertException("该问题已经上传处理结果");
        }

        if (problem.getIfTimeout().equals(1)) {
            throw new AlertException("已逾期,不可上报");
        }

        if (problem.getDealLimitTime().getTime() <= Faster.now().getTime()) {
            throw new AlertException("超过办理截至日期,不能上报");
        }

        ProblemDeal deal = new ProblemDeal();
        deal.setProblemId(problem.getId());
        deal.setDealContent(context);
        deal.setDealImages(imgs);
        deal.setDealImages(imgs);

        deal.setCurrentDepId(problem.getDepId());
        deal.setCurrentDepName(problem.getDepName());
        deal.setDealUsername(name); //处理人
        deal.setDealPhone(dealPhone); //处理人电话

        problem.setIfDeal(1); //已处理
        problem.setDealTime(now); //处理时间
        problem.setDealUsername(name); //处理人
        problem.setDealPhone(dealPhone); //处理人电话
        updateById(problem);

        problemDealService.save(deal);


        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitBatch(List<Integer> proIds, String name, String context, String imgs) throws AlertException {

        Date now = Faster.now();
        for (Integer proId : proIds) {
            Problem problem = getById(proId);
            Faster.throwNull(problem, Err.NF_PROBLEM.n());

            if (problem.getIfAssign().equals(0)) {
                throw new AlertException("该问题尚未分配");
            }

            if (problem.getIfDeal().equals(1)) {
                throw new AlertException("该问题已经上传处理结果");
            }

            ProblemDeal deal = new ProblemDeal();
            deal.setProblemId(problem.getId());
            deal.setDealContent(context);
            deal.setDealImages(imgs);

            deal.setCurrentDepId(problem.getDepId());
            deal.setCurrentDepName(problem.getDepName());
            deal.setDealUsername(name); //处理人

            problem.setIfDeal(1); //已处理
            problem.setDealTime(now); //处理时间
            problem.setDealUsername(name); //处理人
            updateById(problem);

            problemDealService.save(deal);
        }

        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public boolean assess(Integer proId, Integer type) throws AlertException {
        if (type > 0 && type < 4) {

            Problem problem = getById(proId);
            Faster.throwNull(problem, Err.NF_PROBLEM.n());

            if (problem.getIfDeal().equals(0)) {
                throw new AlertException("未处理,不能评价");
            }

            if (problem.getIfAssess().equals(1)) {
                throw new AlertException("已评价,不能重复评价");
            }

            problem.setIfAssess(1); //已评价
            problem.setAssessResult(type); //评价结果
            problem.setAssessTime(Faster.now());
            problem.setIfEnd(1); //已办结
            updateById(problem);

            //更新主信息
            List<Problem> problems = list(new QueryWrapper<Problem>()
                    .select(Problem.IF_END)
                    .eq(Problem.PROBLEM_INFO_ID, problem.getProblemInfoId()));

            boolean match = problems.stream().allMatch(t -> t.getIfEnd().equals(1));

            if (match) {
                //主信息
                problemInfoService.update(new UpdateWrapper<ProblemInfo>()
                        .set(ProblemInfo.IF_ALLEND, 1)
                        .eq(ProblemInfo.PROBLEM_INFO_ID, problem.getProblemInfoId()));
            }
        } else {
            throw new AlertException("未知评价");
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public boolean reassess(Integer proId, Integer type) throws AlertException {
        if (type > 0 && type < 4) {
            Problem problem = getById(proId);
            Faster.throwNull(problem, Err.NF_PROBLEM.n());
            if (1 != problem.getIfAssess()) {
                throw new AlertException("未评价，无法重新评价");
            }

            problem.setAssessResult(type);
            problem.setAssessTime(Faster.now());

            updateById(problem);
        } else {
            throw new AlertException("未知评价");
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean assessBatch(List<Integer> proIds, Integer type) throws AlertException {
        for (Integer proId : proIds) {
            assess(proId, type);
        }
        return true;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean returnBack(Integer ProId, String info) throws AlertException {

        Problem pro = getById(ProId);
        Faster.throwNull(pro, Err.NF_DEAL.n());

        ProblemDeal deal = problemDealService.getOne(new QueryWrapper<ProblemDeal>()
                .eq(ProblemDeal.PROBLEM_ID, pro.getId()).orderByDesc(ProblemDeal.CREATE_TIME)
                .last("LIMIT 0, 1"));

        Faster.throwNull(deal, Err.NF_DEAL.n());

        pro.setIfDeal(2); //打回处理

        deal.setBack2dealContent(info); //批复
        deal.setBack2dealTime(Faster.now()); //打回时间
        problemDealService.updateById(deal);
        updateById(pro);

        return true;
    }

    @Override
    public IPage<ProblemVo> pageNex(IPage<Problem> page, QueryWrapper<Problem> queryWrapper) {
        IPage<Problem> iPage = page(page, queryWrapper);

        IPage<ProblemVo> voIPage = new Page<>();
        List<ProblemVo> reu = new ArrayList<>();

        if (!page.getRecords().isEmpty()) {

            page.getRecords().forEach(t -> {
                ProblemVo problemVo = new ProblemVo();
                BeanUtils.copyProperties(t, problemVo);

                ProblemDeal one = problemDealService.getOne(new QueryWrapper<ProblemDeal>() //最新处理结果
                        .select(ProblemDeal.DEAL_CONTENT)
                        .eq(ProblemDeal.PROBLEM_ID, t.getId())
                        .orderByDesc(ProblemDeal.CREATE_TIME).last("limit 0,1"));

                if (Faster.isNotNull(one)) {
                    problemVo.setDealContent(one.getDealContent());
                } else {
                    problemVo.setDealContent("");
                }

                problemVo.setAssessResultCon(ScoreEnum.result(problemVo.getAssessResult()));
                reu.add(problemVo);
            });
        }

        voIPage.setRecords(reu);
        voIPage.setCurrent(iPage.getCurrent());
        voIPage.setTotal(iPage.getTotal());
        voIPage.setPages(iPage.getPages());
        voIPage.setSize(iPage.getSize());

        return voIPage;
    }

    /**
     * 数据统计区---------------------------------------------------------------------------------------------------
     */

    @Override
    public List<List<Serializable>> trend(String dateType, Calendar cld, Integer status) throws AlertException {

        List<List<Serializable>> lists = new ArrayList<>();

        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        LinkedList<Serializable> dates = Dates.initTrend(dateType, cld);

        SysUser user = sysUserService.getById(SysUtils.currentUserId());

        for (IndustryCategory value : IndustryCategory.values()) {

            List<Serializable> list = new ArrayList<>();
            list.add(value.n());

            /**---逻辑判断区----------------------------------*/
            QueryWrapper<ProblemInfo> queryWrapper = new QueryWrapper<ProblemInfo>()
                    .select(ProblemInfo.PROBLEM_INFO_ID, ProblemInfo.CREATE_TIME, ProblemInfo.REPORT_TIME);
            //id , 创建时间 ,上报时间

            if (status.equals(1)) {  //录入趋势图

                queryWrapper.eq(ProblemInfo.REPORT_DEP_ID, user.getDepId());

                if (Faster.isNotNull(strAndEnd)) {
                    queryWrapper.between(ProblemInfo.CREATE_TIME, strAndEnd[0], strAndEnd[1]);
                }

            } else if (status.equals(2)) { //主控领导趋势图

                queryWrapper.eq(ProblemInfo.IF_REPORT, 2); //上报通过的

                if (Faster.isNotNull(strAndEnd)) {
                    queryWrapper.between(ProblemInfo.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
                }

            } else if (status.equals(3)) { //执行领导趋势图

                queryWrapper.eq(ProblemInfo.IF_REPORT, 2) //上报通过的
                        .eq(ProblemInfo.REPORT_DEP_ID, user.getDepId()); //自己部门上报的

                if (Faster.isNotNull(strAndEnd)) {
                    queryWrapper.between(ProblemInfo.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
                }
            }

            queryWrapper.eq(ProblemInfo.INDUSTRY_CATEGORY, value.n());

            /**----逻辑判断区结束---------------------------------*/

            List<ProblemInfo> temps = problemInfoMapper.selectList(queryWrapper);

            for (Serializable date : dates) {
                int i = 0;
                for (ProblemInfo pro : temps) {

                    if (status.equals(1)) {
                        //录入趋势图根据创建时间
                        if (Dates.format().format(pro.getCreateTime()).equals(date)) {
                            i = i + 1;
                        }
                    } else if (status.equals(2) || status.equals(3)) {
                        //主控领导和执行领导 趋势图根据上报时间
                        if (Dates.format().format(pro.getReportTime()).equals(date)) {
                            i = i + 1;
                        }
                    }
                }
                list.add(i);
            }
            lists.add(list);
        }

        dates.addFirst("0");
        lists.add(dates);
        return lists;
    }

    @Override
    public List<ProblemPieCount> pieCount(String dateType, Calendar cld) throws AlertException {

        List<ProblemPieCount> pies = new ArrayList<>();

        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        for (IndustryCategory value : IndustryCategory.values()) {

            ProblemPieCount pie = new ProblemPieCount();

            pie.setName(value.n());

            QueryWrapper<ProblemInfo> eq_temp = new QueryWrapper<ProblemInfo>()
                    .select(ProblemInfo.CREATE_TIME)
                    .eq(ProblemInfo.REPORT_DEP_ID, SysUtils.currentUser().getDepId());

            eq_temp.eq(ProblemInfo.INDUSTRY_CATEGORY, value.n());

            if (null != strAndEnd) {
                eq_temp.between(ProblemInfo.CREATE_TIME, strAndEnd[0], strAndEnd[1]);
            }

            List<ProblemInfo> problemInfos = problemInfoMapper.selectList(eq_temp);

            pie.setValue(problemInfos.size());
            pies.add(pie);
        }

        return pies;
    }

    @Override
    public ProblemCountGlobal countInput(String dateType, Calendar cld) throws AlertException {

        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        QueryWrapper<ProblemInfo> eq = new QueryWrapper<ProblemInfo>()
                .select(ProblemInfo.IF_REPORT, ProblemInfo.CREATE_TIME)

                .eq(ProblemInfo.REPORT_DEP_ID, SysUtils.currentUser().getDepId());

        if (null != strAndEnd) {
            eq.between(ProblemInfo.CREATE_TIME, strAndEnd[0], strAndEnd[1]);
        }

        List<ProblemInfo> problemInfos = problemInfoMapper.selectList(eq);

        ProblemCountGlobal global = new ProblemCountGlobal();

        global.setAll(problemInfos.size());
        global.setDateType(dateType); //时间类型

        problemInfos.forEach(t -> {
            if (t.getIfReport().equals(2)) {
                global.setPastReport(global.getPastReport() + 1);
            } else {
                global.setNotReport(global.getNotReport() + 1);
            }
        });

        for (IndustryCategory value : IndustryCategory.values()) {
            QueryWrapper<ProblemInfo> eq_temp = new QueryWrapper<ProblemInfo>()
                    .select(ProblemInfo.IF_REPORT, ProblemInfo.CREATE_TIME)
                    .eq(ProblemInfo.REPORT_DEP_ID, SysUtils.currentUser().getDepId());

            eq_temp.eq(ProblemInfo.INDUSTRY_CATEGORY, value.n());

            if (null != strAndEnd) {
                eq_temp.between(ProblemInfo.CREATE_TIME, strAndEnd[0], strAndEnd[1]);
            }

            List<ProblemInfo> temps = problemInfoMapper.selectList(eq_temp);

            ProblemCountType type = new ProblemCountType();

            type.setTypeName(value.n());
            type.setAll(temps.size());

            temps.forEach(x -> {
                if (x.getIfReport().equals(2)) {
                    type.setPastReport(type.getPastReport() + 1);
                } else {
                    type.setNotReport(type.getNotReport() + 1);
                }
            });
            type.setPercent(Faster.getPercentage(type.getPastReport(), type.getAll()));//计算百分比

            global.getProblemCountTypes().add(type);
        }
        return global;
    }


    @Override
    public ProblemGlobal countLeader(String dateType, Calendar cld) throws AlertException {
        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        ProblemGlobal global = new ProblemGlobal();

        QueryWrapper<ProblemInfo> eq = new QueryWrapper<ProblemInfo>()
                .eq(ProblemInfo.IF_REPORT, 2); //上报通过的

        if (null != strAndEnd) {
            eq.between(ProblemInfo.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
        }

        Integer selectCount = problemInfoMapper.selectCount(eq);

        global.setAll(selectCount); //上报问题数量
        global.setDateType(dateType); //时间类型

        if (selectCount != 0) {
            QueryWrapper<Problem> qw1 = new QueryWrapper<Problem>()
                    .select(Problem.IF_ASSESS, Problem.ASSESS_RESULT)
                    .eq(Problem.IF_DEAL, 1);

            if (null != strAndEnd) {  //时间限制
                qw1.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
            }

            List<Problem> list = baseMapper.selectList(qw1);

            global.setProcess(list.size()); //已处理问题数量

            int pleased = 0; //满意数量

            for (Problem t : list) {
                if (t.getAssessResult().equals(1) || t.getAssessResult().equals(2)) {
                    //满意 || 基本满意
                    pleased += 1;
                }
            }

            //计算满意度
            global.setPleased(Faster.getPercentage(pleased, global.getProcess()));

            for (IndustryCategory value : IndustryCategory.values()) {

                ProblemType temp = new ProblemType();
                temp.setTypeName(value.n());

                QueryWrapper<ProblemInfo> eq2 = new QueryWrapper<ProblemInfo>()
                        .eq(ProblemInfo.IF_REPORT, 2)
                        .eq(ProblemInfo.INDUSTRY_CATEGORY, value.n());

                if (null != strAndEnd) {  //时间限制
                    eq2.between(Problem.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
                }

                //上报数量
                temp.setAll(problemInfoMapper.selectCount(eq2));

                QueryWrapper<Problem> qw3 = new QueryWrapper<Problem>()
                        .eq(Problem.IF_DEAL, 1)
                        .eq(ProblemInfo.INDUSTRY_CATEGORY, value.n());

                if (null != strAndEnd) {  //时间限制
                    qw3.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
                }

                //处理数量
                temp.setProcess(baseMapper.selectCount(qw3));
                global.getProblemTypes().add(temp);
            }
        }
        return global;
    }

    @Override
    public ProblemGlobal countExecute(String dateType, Calendar cld) throws AlertException {
        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        ProblemGlobal global = new ProblemGlobal();

        SysUser user = sysUserService.getById(SysUtils.currentUserId());

        QueryWrapper<Problem> eq = new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, user.getDepId())
                .eq(Problem.IF_ASSIGN, 1);

        if (null != strAndEnd) {
            eq.between(Problem.ASSIGN_TIME, strAndEnd[0], strAndEnd[1]);
        }

        Integer selectCount = baseMapper.selectCount(eq);
        //已分配的问题数量
        global.setAll(selectCount);
        //时间类型
        global.setDateType(dateType);

        QueryWrapper<Problem> eq2 = new QueryWrapper<Problem>()
                .select(Problem.IF_ASSESS, Problem.ASSESS_RESULT)
                .eq(Problem.DEP_ID, user.getDepId())
                .eq(Problem.IF_ASSIGN, 1)
                .eq(Problem.IF_DEAL, 1);

        if (null != strAndEnd) {
            eq2.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
        }

        List<Problem> list = baseMapper.selectList(eq2);

        //已处理问题数量
        global.setProcess(list.size());

        int pleased = 0; //满意数量
        for (Problem t : list) {
            if (t.getAssessResult().equals(1) || t.getAssessResult().equals(2)) {
                //满意 || 基本满意
                pleased += 1;
            }
        }

        //计算满意度
        global.setPleased(Faster.getPercentage(pleased, global.getProcess()));

        for (IndustryCategory value : IndustryCategory.values()) {

            ProblemType temp = new ProblemType();
            temp.setTypeName(value.n());

            QueryWrapper<ProblemInfo> eq3 = new QueryWrapper<ProblemInfo>()
                    .eq(ProblemInfo.IF_REPORT, 2) //上报通过的
                    .eq(ProblemInfo.INDUSTRY_CATEGORY, value.n())
                    .eq(ProblemInfo.REPORT_DEP_ID, user.getDepId());

            if (null != strAndEnd) {
                eq3.between(ProblemInfo.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
            }

            //上报数量
            temp.setAll(problemInfoMapper.selectCount(eq3));

            QueryWrapper<Problem> eq4 = new QueryWrapper<Problem>()
                    .eq(Problem.IF_DEAL, 1)
                    .eq(Problem.INDUSTRY_CATEGORY, value.n())
                    .eq(Problem.DEP_ID, user.getDepId());

            if (null != strAndEnd) {  //时间限制
                eq4.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
            }

            //处理数量
            temp.setProcess(baseMapper.selectCount(eq4));

            global.getProblemTypes().add(temp);
        }


        return global;
    }


    /**
     * 主控 领导页面下半部分基础统计
     *
     * @return
     */
    private List<DeptCount> baseDeptCount(String dateType, Calendar cld) {

        List<DeptCount> sortCounts = new ArrayList<>();

        List<Department> departments =
                departmentService.list(new QueryWrapper<Department>().select(Department.DEP_NAME));

        if (!departments.isEmpty()) {

            String[] strAndEnd = Dates.strAndEnd(dateType, cld);

            departments.forEach(t -> {

                DeptCount sortCount = new DeptCount();
                sortCount.setDepName(t.getDepName());

                QueryWrapper<Problem> eq = new QueryWrapper<Problem>()
                        .select(Problem.IF_DEAL, Problem.ASSESS_RESULT)
                        .eq(Problem.DEP_NAME, t.getDepName())
                        .eq(Problem.IF_REPORT, 2)
                        .eq(Problem.IF_ASSIGN, 1);

                if (null != strAndEnd) {
                    eq.between(Problem.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
                }

                List<Problem> problems = baseMapper.selectList(eq);

                sortCount.setAll(problems.size());


                QueryWrapper<Problem> eq1 = new QueryWrapper<Problem>()
                        .eq(Problem.REPORT_DEP_NAME, t.getDepName())
                        .eq(Problem.IF_REPORT, 2);
                if (null != strAndEnd) {
                    eq1.between(Problem.REPORT_TIME, strAndEnd[0], strAndEnd[1]);
                }
                sortCount.setReport(baseMapper.selectCount(eq1)); //上报数量


                if (!problems.isEmpty()) {
                    int pleased = 0; //满意数量

                    for (Problem x : problems) {
                        if (x.getIfDeal().equals(1)) { //已处理
                            sortCount.setProcess(sortCount.getProcess() + 1);

                            if (x.getAssessResult().equals(1) || x.getAssessResult().equals(2)) {
                                //满意 || 基本满意
                                pleased += 1;
                            }
                        }
                    }
                    //计算满意度
                    sortCount.setPleased(Faster.getPercentage(pleased, sortCount.getProcess()));

                    //处理数量百分比
                    sortCount.setPercent(Faster.getPercentage(sortCount.getProcess(), sortCount.getAll()));
                }

                sortCounts.add(sortCount);
            });
        }

        return sortCounts;

    }

    @Override
    public List<DeptCount> sortCountDept(Integer sort, String type, Calendar cld) throws AlertException {

        List<DeptCount> deptCounts = baseDeptCount(type, cld);

        if (sort.equals(1)) {

            deptCounts.sort((a, b) -> b.getReport().compareTo(a.getReport()));
        } else if (sort.equals(2)) {

            deptCounts.sort((a, b) -> b.getProcess().compareTo(a.getProcess()));

        } else if (sort.equals(3)) {

            deptCounts.sort((a, b) -> b.getPleased().compareTo(a.getPleased()));
        } else if (sort.equals(4)) {
            deptCounts.sort((a, b) -> b.getPercent().compareTo(a.getPercent()));
        }

        return deptCounts;
    }

    @Override
    public List<DeptCount> othCountDept(String type, Calendar cld) throws AlertException {

        List<DeptCount> deptCounts = baseDeptCount(type, cld);
        return deptCounts;
    }


    /**
     * 执行领导页面下面基础统计
     */
    private List<EmpCount> baseEmpCount(String dateType, Calendar cld) {

        List<EmpCount> sortCounts = new ArrayList<>();

        SysUser user = sysUserService.getById(SysUtils.currentUserId());

        String[] strAndEnd = Dates.strAndEnd(dateType, cld);

        QueryWrapper<Problem> eq_user = new QueryWrapper<Problem>()
                .select(Problem.DEAL_USERNAME)
                .isNotNull(Problem.DEAL_USERNAME)
                .eq(Problem.DEP_ID, user.getDepId()) //当前部门下的
                .eq(Problem.IF_DEAL, 1)       //已处理
                .groupBy(Problem.DEAL_USERNAME);

        if (null != strAndEnd) {
            eq_user.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
        }

        List<Problem> users = baseMapper.selectList(eq_user);

        if (!users.isEmpty()) {

            users.forEach(t -> {

                EmpCount sortCount = new EmpCount();
                sortCount.setName(t.getDealUsername());

                QueryWrapper<Problem> eq_u = new QueryWrapper<Problem>()
                        .select(Problem.ASSESS_RESULT)
                        .eq(Problem.DEAL_USERNAME, t.getDealUsername())
                        .eq(Problem.DEP_ID, user.getDepId()) //当前部门下的
                        .eq(Problem.IF_DEAL, 1);  //已处理的

                if (null != strAndEnd) {
                    eq_u.between(Problem.DEAL_TIME, strAndEnd[0], strAndEnd[1]);
                }

                List<Problem> problems = baseMapper.selectList(eq_u);

                sortCount.setProcess(problems.size());

                if (!problems.isEmpty()) {

                    int pleased = 0; //满意数量

                    for (Problem x : problems) {
                        if (x.getAssessResult().equals(1) || x.getAssessResult().equals(2)) {
                            //满意 || 基本满意
                            pleased += 1;
                        }
                    }
                    sortCount.setPleased(Faster.getPercentage(pleased, sortCount.getProcess())); //计算满意度
                }
                sortCounts.add(sortCount);
            });
        }
        return sortCounts;
    }


    @Override
    public List<EmpCount> sortCountEmp(Integer sort, String dateType, Calendar cld) throws AlertException {

        List<EmpCount> empCounts = baseEmpCount(dateType, cld);

        if (sort.equals(2)) {
            empCounts.sort((a, b) -> b.getProcess().compareTo(a.getProcess()));

        } else if (sort.equals(3)) {
            empCounts.sort((a, b) -> b.getPleased().compareTo(a.getPleased()));
        }
        return empCounts;
    }

    @Override
    public List<EmpCount> othCountEmp(String dateType, Calendar cld) throws AlertException {
        List<EmpCount> empCounts = baseEmpCount(dateType, cld);
        return empCounts;
    }

    /**
     * 总控部门统计信息如下：
     * <p>
     * 1. 今日问题上报数量：主信息（problem_info），时间筛选为当天 上报状态为 除了未上报的（if_report >0）
     * <p>
     * 2. 今日结果上报数量：problem_deal 时间筛选为当天
     * <p>
     * 3. 今日难度上报数量：子信息 problem，时间（difficult_level_submit_time）筛选为当天  difficult_level_status>0
     * <p>
     * 4. 今日疑难件申请数量：problem_apply 筛选当天的疑难件申请数量
     * <p>
     * 待处理问题：总数直接等于各个分项的和
     * <p>
     * 1. 上报待审批：子信息 所有 上报状态为 待审批的
     * <p>
     * 2. 难度待审批：子信息 所有 办理难度状态为 待审批的
     * <p>
     * 3. 疑难件待审批：所有待审批的疑难件申请数量
     * <p>
     * 4. 结果待评分：所有已处理 未评分的子信息数
     * <p>
     * 已处理问题：总数直接等于各个分项的和
     * <p>
     * 1. 上报审批：主信息 所有 上报状态为 除了待审批的
     * <p>
     * 2. 难度审批：子信息 所有 办理难度状态为 除了待审批的
     * <p>
     * 3. 疑难件审批：所有审批通过的疑难件申请数量
     * <p>
     * 4. 结果评分：所有已评分的子信息数
     */
    @Override
    public TotalCount totalCount() {

        TotalCount totalCount = new TotalCount();
        //今天
        String today = Dates.format().format(Faster.now());

        totalCount.setToReport(problemInfoMapper.selectCount(new QueryWrapper<ProblemInfo>()
                .gt(ProblemInfo.IF_REPORT, 0).likeRight(ProblemInfo.REPORT_TIME, today)));

        totalCount.setToEnd(problemDealMapper.selectCount(new QueryWrapper<ProblemDeal>()
                .likeRight(ProblemDeal.CREATE_TIME, today)));

        totalCount.setToLevel(baseMapper.selectCount(new QueryWrapper<Problem>()
                .gt(Problem.DIFFICULT_LEVEL_STATUS, 0).likeRight(Problem.DIFFICULT_LEVEL_SUBMIT_TIME, today)));

        totalCount.setToDiff(problemApplyMapper.selectCount(new QueryWrapper<ProblemApply>().likeRight(ProblemApply.CREATE_TIME, today)));

        totalCount.setReportInVerify(baseMapper.selectCount(new QueryWrapper<Problem>().eq(Problem.IF_REPORT, 1)));

        totalCount.setLeveInVerify(baseMapper.selectCount(new QueryWrapper<Problem>().eq(Problem.DIFFICULT_LEVEL_STATUS, 1)));

        totalCount.setDiffInVerify(problemApplyMapper.selectCount(new QueryWrapper<ProblemApply>().eq(ProblemApply.APPLY_STATUS, 0)));

        totalCount.setDealInScore(baseMapper.selectCount(new QueryWrapper<Problem>().eq(Problem.IF_DEAL, 1).eq(Problem.IF_ASSESS, 0)));

        totalCount.setNoDealAll(totalCount.getReportInVerify() + totalCount.getLeveInVerify()
                + totalCount.getDiffInVerify() + totalCount.getDealInScore());

        //计算进度条百分比
        totalCount.setReportInVerifyPer(Faster.getPercentage(totalCount.getReportInVerify(), totalCount.getNoDealAll()));
        totalCount.setLeveInVerifyPer(Faster.getPercentage(totalCount.getLeveInVerify(), totalCount.getNoDealAll()));
        totalCount.setDiffInVerifyPer(Faster.getPercentage(totalCount.getDiffInVerify(), totalCount.getNoDealAll()));
        totalCount.setDealInScorePer(Faster.getPercentage(totalCount.getDealInScore(), totalCount.getNoDealAll()));

        totalCount.setReportIs(problemInfoMapper.selectCount(new QueryWrapper<ProblemInfo>().ne(ProblemInfo.IF_REPORT, 1)));
        totalCount.setLeverIs(baseMapper.selectCount(new QueryWrapper<Problem>().ne(Problem.DIFFICULT_LEVEL_STATUS, 1)));
        totalCount.setDiffIs(problemApplyMapper.selectCount(new QueryWrapper<ProblemApply>().eq(ProblemApply.APPLY_STATUS, 1)));
        totalCount.setDealIs(baseMapper.selectCount(new QueryWrapper<Problem>().eq(Problem.IF_ASSESS, 1)));

        totalCount.setAlreadyDealAll(totalCount.getReportIs() + totalCount.getLeverIs() +
                totalCount.getDiffIs() + totalCount.getDealIs());

        //计算进度条百分比
        totalCount.setReportIsPer(Faster.getPercentage(totalCount.getReportIs(), totalCount.getAlreadyDealAll()));
        totalCount.setLeverIsPer(Faster.getPercentage(totalCount.getLeverIs(), totalCount.getAlreadyDealAll()));
        totalCount.setDiffIsPer(Faster.getPercentage(totalCount.getDiffIs(), totalCount.getAlreadyDealAll()));
        totalCount.setDealIsPer(Faster.getPercentage(totalCount.getDealIs(), totalCount.getAlreadyDealAll()));


        return totalCount;
    }


    /**
     * 执行部门首页统计数据如下：
     * <p>
     * 1. 今日问题上报数量：主信息（problem_info），上报部门是当前部门，时间筛选为当天 上报状态为 除了未上报的（if_report >0）
     * <p>
     * 2. 今日问题办结数量：problem_deal ，处理部门为当前部门，时间筛选为当天（今天本部门上报了处理结果的总数量）
     * <p>
     * 3. 即将逾期问题数量：子信息 problem，处理部门为当前部门，逾期状态为即将逾期的，所有子问题的数量
     * <p>
     * 4. 今日被分配问题数量：子问题 ，处理部门为本部门，分配时间是当天的子问题数量（今日分配到本部门的子问题数）
     * <p>
     * 待审批问题：总数直接等于各个分项的和
     * <p>
     * 1. 上报待审批： 上报部门为本部门的，所有 上报状态为 待审批的的子问题数量
     * <p>
     * 2. 难度待审批： 处理部门为本部门的，所有 办理难度状态为 待审批的的子问题数量
     * <p>
     * 3. 疑难件待审批：处理部门为本部门的， 所有待审批的疑难件申请数量
     * <p>
     * 4. 结果待评分：处理部门为本部门的，所有已处理 未评分的子信息数
     * <p>
     * <p>
     * 待办理问题：总数直接等于各个分项的和
     * <p>
     * 1. 正常办理问题：处理部门为本部门的，逾期状态为 未逾期 的，处理状态为 未处理 或 打回处理 的子信息 的数量  (难度通过的,未办结)
     * <p>
     * 2. 即将逾期：处理部门为本部门的，逾期状态为 即将逾期 的，处理状态为 未处理 或 打回处理 的子信息 的数量 (难度通过的)
     * <p>
     * 3. 已逾期：处理部门为本部门的，逾期状态为 已逾期 的的子信息的数量 (难度通过的)
     */
    @Override
    public ExecuteCount executeCount() {
        ExecuteCount executeCount = new ExecuteCount();
        //今天
        String today = Dates.format().format(Faster.now());

        SysUser sysUser = SysUtils.currentUser();

        executeCount.setToReport(problemInfoMapper.selectCount(new QueryWrapper<ProblemInfo>()
                .gt(ProblemInfo.IF_REPORT, 0).eq(ProblemInfo.REPORT_DEP_ID, sysUser.getDepId())
                .likeRight(ProblemInfo.REPORT_TIME, today)));

        executeCount.setToEnd(problemDealMapper.selectCount(new QueryWrapper<ProblemDeal>()
                .eq(ProblemDeal.CURRENT_DEP_ID, sysUser.getDepId())
                .likeRight(ProblemDeal.CREATE_TIME, today)));

        executeCount.setNear(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId())
                .gt(Problem.IF_TIMEOUT, 2)));

        executeCount.setToAssign(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId())
                .likeRight(Problem.ASSIGN_TIME, today)));


        executeCount.setReportInVerify(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId()).eq(Problem.IF_REPORT, 1)));

        executeCount.setLevelInVerify(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId()).eq(Problem.DIFFICULT_LEVEL_STATUS, 1)));

        executeCount.setDiffInVerify(problemApplyMapper.selectCount(new QueryWrapper<ProblemApply>()
                .eq(ProblemApply.CURRENT_DEP_ID, sysUser.getDepId()).eq(ProblemApply.APPLY_STATUS, 0)));

        executeCount.setDealInScore(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId()).eq(Problem.IF_DEAL, 1)
                .eq(Problem.IF_ASSESS, 0)));

        executeCount.setNoVerifyAll(executeCount.getReportInVerify() + executeCount.getLevelInVerify()
                + executeCount.getDiffInVerify() + executeCount.getDealInScore());

        executeCount.setReportInVerifyPer(Faster.getPercentage(executeCount.getReportInVerify(), executeCount.getNoVerifyAll()));
        executeCount.setLevelInVerifyPer(Faster.getPercentage(executeCount.getLevelInVerify(), executeCount.getNoVerifyAll()));
        executeCount.setDiffInVerifyPer(Faster.getPercentage(executeCount.getDiffInVerify(), executeCount.getNoVerifyAll()));
        executeCount.setDealInScorePer(Faster.getPercentage(executeCount.getDealInScore(), executeCount.getNoVerifyAll()));

        executeCount.setNormalIs(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId()).eq(Problem.IF_TIMEOUT, 0)
                .eq(Problem.DIFFICULT_LEVEL_STATUS, 2)
                .eq(Problem.IF_END, 0)
                .in(Problem.IF_DEAL, 0, 2)));

        executeCount.setNearIs(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId())
                .eq(Problem.DIFFICULT_LEVEL_STATUS, 2)
                .eq(Problem.IF_TIMEOUT, 2)
                .eq(Problem.IF_END, 0)
                .in(Problem.IF_DEAL, 0, 2)));

        executeCount.setAlreadyIs(baseMapper.selectCount(new QueryWrapper<Problem>()
                .eq(Problem.DEP_ID, sysUser.getDepId())
                .eq(Problem.DIFFICULT_LEVEL_STATUS, 2)
                .eq(Problem.IF_TIMEOUT, 1)));

        executeCount.setNoDealAll(executeCount.getNormalIs() + executeCount.getNearIs() + executeCount.getAlreadyIs());

        executeCount.setNormalIsPer(Faster.getPercentage(executeCount.getNormalIs(), executeCount.getNoDealAll()));
        executeCount.setNearIsPer(Faster.getPercentage(executeCount.getNearIs(), executeCount.getNoDealAll()));
        executeCount.setAlreadyIsPer(Faster.getPercentage(executeCount.getAlreadyIs(), executeCount.getNoDealAll()));

        return executeCount;
    }
}
